AllKinds tests: cargo-run
authorBen Wiederhake <BenWiederhake.GitHub@gmx.de>
Fri, 24 Mar 2017 20:20:38 +0000 (21:20 +0100)
committerBen Wiederhake <BenWiederhake.GitHub@gmx.de>
Mon, 10 Apr 2017 18:20:32 +0000 (20:20 +0200)
tests/run.rs

index 53252a0682f3d4934cc94ae8d630a5a35d133e5e..83d957b814c1eaf6f9bb130d0d1c1c0dca606506 100644 (file)
@@ -31,6 +31,32 @@ hello
     assert_that(&p.bin("foo"), existing_file());
 }
 
+#[test]
+#[ignore]
+fn simple_implicit_main() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", r#"
+            fn main() { println!("hello world"); }
+        "#);
+
+    assert_that(p.cargo_process("run").arg("--bins"),
+                execs().with_status(0)
+                       .with_stderr(&format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[RUNNING] `target[/]debug[/]foo[EXE]`", dir = path2url(p.root())))
+                       .with_stdout("\
+hello
+"));
+    assert_that(&p.bin("foo"), existing_file());
+}
+
 #[test]
 fn simple_quiet() {
     let p = project("foo")
@@ -184,6 +210,24 @@ fn no_main_file() {
                                      for `cargo run`\n"));
 }
 
+#[test]
+#[ignore]
+fn no_main_file_implicit() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "");
+
+    assert_that(p.cargo_process("run").arg("--bins"),
+                execs().with_status(101)
+                       .with_stderr("[ERROR] a bin target must be available \
+                                     for `cargo run`\n"));
+}
+
 #[test]
 fn too_many_bins() {
     let p = project("foo")
@@ -204,6 +248,27 @@ fn too_many_bins() {
                                      to specify which one to run\n"));
 }
 
+#[test]
+#[ignore]
+fn too_many_bins_implicit() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file("src/bin/a.rs", "")
+        .file("src/bin/b.rs", "");
+
+    assert_that(p.cargo_process("run").arg("--bins"),
+                execs().with_status(101)
+                       .with_stderr("[ERROR] `cargo run` requires that a project only \
+                                     have one executable; use the `--bin` option \
+                                     to specify which one to run\n"));
+}
+
 #[test]
 fn specify_name() {
     let p = project("foo")
@@ -275,6 +340,64 @@ example
 "));
 }
 
+#[test]
+#[ignore]
+fn run_bin_implicit() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file("examples/a.rs", r#"
+            fn main() { println!("example"); }
+        "#)
+        .file("src/bin/a.rs", r#"
+            fn main() { println!("bin"); }
+        "#);
+
+    assert_that(p.cargo_process("run").arg("--bins"),
+                execs().with_status(0)
+                       .with_stderr(&format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[RUNNING] `target[/]debug[/]examples[/]a[EXE]`", dir = path2url(p.root())))
+                       .with_stdout("\
+bin
+"));
+}
+
+#[test]
+#[ignore]
+fn run_example_implicit() {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/lib.rs", "")
+        .file("examples/a.rs", r#"
+            fn main() { println!("example"); }
+        "#)
+        .file("src/bin/a.rs", r#"
+            fn main() { println!("bin"); }
+        "#);
+
+    assert_that(p.cargo_process("run").arg("--examples"),
+                execs().with_status(0)
+                       .with_stderr(&format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+[RUNNING] `target[/]debug[/]examples[/]a[EXE]`", dir = path2url(p.root())))
+                       .with_stdout("\
+example
+"));
+}
+
 #[test]
 fn run_with_filename() {
     let p = project("foo")